from django.contrib import admin
from .models import Document, DocumentCategory, DocumentVersion

class DocumentVersionInline(admin.StackedInline):
    model = DocumentVersion
    extra = 1

@admin.register(Document)
class DocumentAdmin(admin.ModelAdmin):
    list_display = ('title', 'category', 'status', 'created_by', 'created_at')
    list_filter = ('status', 'category', 'created_at')
    search_fields = ('title', 'content', 'tags', 'description')
    inlines = [DocumentVersionInline]
    fieldsets = (
        ('基本信息', {
            'fields': ('title', 'content', 'file', 'category', 'status')
        }),
        ('元数据', {
            'fields': ('tags', 'description'),
            'classes': ('collapse',)
        }),
    )

@admin.register(DocumentCategory)
class DocumentCategoryAdmin(admin.ModelAdmin):
    list_display = ('name', 'parent', 'created_at')
    list_filter = ('parent',)
    search_fields = ('name',)

@admin.register(DocumentVersion)
class DocumentVersionAdmin(admin.ModelAdmin):
    list_display = ('document', 'version_number', 'created_by', 'created_at')
    list_filter = ('created_at',)
    search_fields = ('document__title', 'changes')
